package org.dromara.system.controller.yzl;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.bo.YzlShieldDeviceBo;
import org.dromara.system.domain.vo.YzlShieldDeviceVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.service.IYzlShieldDeviceService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 盾构机设备
 *
 * @author wfy
 * @date 2025-10-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/shieldDevice")
public class YzlShieldDeviceController extends BaseController {

    private final IYzlShieldDeviceService yzlShieldDeviceService;

    /**
     * 查询盾构机设备列表
     */
    @GetMapping("/list")
    public TableDataInfo<YzlShieldDeviceVo> list(YzlShieldDeviceBo bo, PageQuery pageQuery) {
        return yzlShieldDeviceService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出盾构机设备列表
     */
    @Log(title = "盾构机设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(YzlShieldDeviceBo bo, HttpServletResponse response) {
        List<YzlShieldDeviceVo> list = yzlShieldDeviceService.queryList(bo);
        ExcelUtil.exportExcel(list, "盾构机设备", YzlShieldDeviceVo.class, response);
    }

    /**
     * 获取盾构机设备详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<YzlShieldDeviceVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(yzlShieldDeviceService.queryById(id));
    }

    /**
     * 新增盾构机设备
     */
    @Log(title = "盾构机设备", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody YzlShieldDeviceBo bo) {
        bo.setDeptId(LoginHelper.getDeptId());
        bo.setUserId(LoginHelper.getUserId());
        return toAjax(yzlShieldDeviceService.insertByBo(bo));
    }

    /**
     * 修改盾构机设备
     */
    @Log(title = "盾构机设备", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody YzlShieldDeviceBo bo) {
        return toAjax(yzlShieldDeviceService.updateByBo(bo));
    }

    /**
     * 删除盾构机设备
     *
     * @param ids 主键串
     */
    @Log(title = "盾构机设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(yzlShieldDeviceService.deleteWithValidByIds(List.of(ids), true));
    }
}
